<?php 
$image = $shop->CurrentProduct->getImage();
$thumbs = $shop->CurrentProduct->getImageObjects();
if(count($shop->CurrentProduct->getVariations()) > 1)
{
	if(count($shop->CurrentProduct->getAttributesVar()) > 0)
	{
		foreach($shop->CurrentProduct->getAttributesVar() as $att)
        {
			if($_POST['a_'.$att['id'].'_v'] > 0)
			{
				if(isset($shop->CurrentProduct->ImagesByAttributeValueId[$_POST['a_'.$att['id'].'_v']]))
				{
					$image = $shop->CurrentProduct->ImagesByAttributeValueId[$_POST['a_'.$att['id'].'_v']];
					$shop->CurrentProduct->setImage($image);
					$shop->CurrentProduct->setImageObject($shop->CurrentProduct->ImageObjects[$image['id']]);
					unset($thumbs);
				}
			}
			else
			{
				if($_POST['attribute_'.$att['id'].'_value'] > 0)
				{
					if(isset($shop->CurrentProduct->ImagesByAttributeValueId[$_POST['attribute_'.$att['id'].'_value']]))
					{
						$image = $shop->CurrentProduct->ImagesByAttributeValueId[$_POST['attribute_'.$att['id'].'_value']];
						$shop->CurrentProduct->setImage($image);
						$shop->CurrentProduct->setImageObject($shop->CurrentProduct->ImageObjects[$image['id']]);
						unset($thumbs);
					}
				}
			}
		}
	}
	if(count($shop->CurrentProduct->getImagesByVariationId()) > 0)
	{
		if(isset($shop->CurrentProduct->ImagesByVariationId[$shop->CurrentProduct->getCurrentVariationId()]))
		{
			$image = $shop->CurrentProduct->ImagesByVariationId[$shop->CurrentProduct->getCurrentVariationId()];
			$shop->CurrentProduct->setImage($image);
			$shop->CurrentProduct->setImageObject($shop->CurrentProduct->ImageObjects[$image['id']]);
			unset($thumbs);
		}
	}
}

if($shop->CurrentProduct->getImageObject()): ?>
<div class="product_image detail image">
<?php
if(is_file(PRODUCT_PATH.$image['image']))
{ echo '<a href="'.PRODUCT_URL.$image['image'].'" class="fancyBoxGallery thumbnail" rel="gallery_'.$shop->CurrentProduct->getId().'">'; }
if(is_file(PRODUCT_PATH.'thumbs/'.$image['image']))
{ ?><img src="<?php echo $shop->CurrentProduct->getImageObject()->getLink($shop->getSetting('ImageDetailW'), $shop->getSetting('ImageDetailH')); ?>" alt="<?php echo $shop->CurrentProduct->getTitle(); ?>" /><?php }
if(is_file(PRODUCT_PATH.$image['image']))
{ echo '</a>'; }
?><br /><?php /* <g:plusone size="medium" dir="rtl"></g:plusone> */ ?>
</div>
<?php endif; ?>
<?php 
if($thumbs)
{
	?>
	<div class="row hidden-print thumbs">
		<?php
		$i=0;
		foreach($shop->CurrentProduct->getImageObjects() as $img)
		{
			if(!$img->getDefault())
			{
				?>
					<div class="col-md-3">
						<a rel="gallery_<?php echo $shop->CurrentProduct->getId(); ?>" class="fancyBoxGallery thumbnail" href="<?php echo $img->getLink(); ?>?rand=<?php echo rand(1, 10000); ?>"><img alt="<?php echo $txt->getWord('image'); ?>" src="<?php echo $img->getLink($shop->getSetting('ImageDetailThW'), $shop->getSetting('ImageDetailThH')); ?>?rand=<?php echo rand(1, 10000); ?>" itemprop="image" /></a>
					</div>
				<?php 
				//if(($i%6) == 0)
				//{ echo '</div></div><div class="row-fluid visible-desktop"><div class="span12 thumbs">'; }
			}
			$i++;
		}
		?>
	</div>
	<?php
}
?>